package appx.craft.droid.uc;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import appx.craft.droid.R;
import appx.craft.droid.bean.LikersBean;

public class LikersAdapter extends BaseAdapter{

	LayoutInflater mInflater;
	ArrayList<LikersBean> mLikerArrayList;
	Context mContext;
	
	public LikersAdapter(Context context){
		mContext  = context;
		mInflater = LayoutInflater.from(context);
		mLikerArrayList = new ArrayList<LikersBean>();
		
	}
	
	public void addNewLikers(final ArrayList<LikersBean> mListofLikers){
		if(mLikerArrayList != null){
			
			if(!mLikerArrayList.isEmpty()){
				mLikerArrayList.clear();
			}
			
			for(LikersBean mTempBean : mListofLikers){
				mLikerArrayList.add(mTempBean);
			}
			notifyDataSetChanged();
		}
	}
	
	
	
	@Override
	public int getCount() {
		return mLikerArrayList.size();
	}

	@Override
	public Object getItem(int position) {
		return mLikerArrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;

		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.row_item_liker, parent, false);
			holder.textView_first_name = (TextView)convertView.findViewById(R.id.textView_first_name);
			holder.textView_last_name = (TextView)convertView.findViewById(R.id.textView_last_name);
			
			convertView.setTag(holder);
			
		} else {
			
			holder = (ViewHolder) convertView.getTag();
		}
		
		final LikersBean mContentofLiker = mLikerArrayList.get(position);
		if(mContentofLiker != null){
			
			holder.textView_first_name.setText(mContentofLiker.getStrFirstName());
			holder.textView_last_name.setText(mContentofLiker.getStrLastName());
		}
		
		return convertView;
	}
	
	class ViewHolder {
		
		TextView textView_last_name;
		TextView textView_first_name;
		ImageView imageView_likers;
	}

}
